package userModuleApi

import (
	"KumquatDrivesServices/common/res"
	"KumquatDrivesServices/global"
	"KumquatDrivesServices/model"
	"KumquatDrivesServices/utils"
	"errors"
	"github.com/gin-gonic/gin"
	"github.com/sirupsen/logrus"
	"gorm.io/gorm"
)

func (UserModuleApi) GetUserInfo(c *gin.Context) {
	userId := utils.GetUserId(c)
	var userModel model.UserModel
	if err := global.DB.Where("id=?", userId).First(&userModel).Error; err != nil {
		if errors.Is(err, gorm.ErrRecordNotFound) {
			res.FailWithCode(res.USER_NOT_EXIST, c)
			return
		}
		logrus.Errorf("get user info error: %v", err)
		res.FailWithCode(res.SYS_ERR, c)
		return
	}
	res.OkWithData(userModel, c)
}
